import React, { useEffect, useRef, useState } from 'react'

export default function ClostureUseState() {
    const [count, setCount] = useState(0)
    const countRef = useRef()
    countRef.current = count
    const handleCountClick = () => {
        setCount(pre => {
            return pre + 1
        })
        setTimeout(()=>{
            console.log(count,'修改后的值');
            console.log(countRef,'修改后的值');
        },0)
    }
    useEffect(()=>{
        console.log(count,'useEffect修改后的值');
        console.log(countRef,'useEffect修改后的值');
    },[count])
    return (
        <div>
            <h1>{count}</h1>
            <button onClick={handleCountClick}>修改</button>
        </div>
    )
}
